package com.zhku.goods.controller;


import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.goods.model.dto.GoodsDto;
import com.zhku.goods.model.po.TtGoods;
import com.zhku.goods.service.TtGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(value = "商品相关接口",tags = "商品相关接口")
@RestController
public class TtGoodsController {

    @Autowired
    private TtGoodsService ttGoodsService;

    @ApiOperation("新增商品接口")
    @PostMapping("/createGoods")
    public RestResponse<TtGoods> createGoods(@RequestBody GoodsDto goodsDto){
        TtGoods ttGoods = ttGoodsService.createGoods(goodsDto);
        return RestResponse.success(ttGoods);
    }

    @ApiOperation("修改商品接口")
    @PostMapping("/updateGoods")
    public RestResponse<TtGoods> updateGoods(@RequestBody TtGoods ttGoods){
        TtGoods ttGoodsNew = ttGoodsService.updateGoods(ttGoods);
        return RestResponse.success(ttGoodsNew);
    }

    @ApiOperation("查询商品接口")
    @GetMapping("/goods/{id}")
    public RestResponse<TtGoods> getGoods(@PathVariable("id") String id){
        TtGoods ttGoods = ttGoodsService.getShop(id);
        return RestResponse.success(ttGoods);
    }

    @ApiOperation("根据传入的店铺id分页查询该店铺有哪些商品")
    @PostMapping("/goodsList/{id}")
    public PageResult<TtGoods> goodsList(@RequestBody(required = false)PageParams pageParams,@PathVariable("id") String id){
        PageResult<TtGoods> list = ttGoodsService.getGoodsList(pageParams,id);
        return list;
    }

    @ApiOperation("商品上架")
    @PostMapping("/goodsUp/{id}")
    public RestResponse<TtGoods> goodsUp(@PathVariable("id")String id){
        TtGoods ttGoods = ttGoodsService.goodsUp(id);
        return RestResponse.success(ttGoods);
    }

    @ApiOperation("商品下架")
    @PostMapping("/goodsDown/{id}")
    public RestResponse<TtGoods> goodsDown(@PathVariable("id")String id){
        TtGoods ttGoods = ttGoodsService.goodsDown(id);
        return RestResponse.success(ttGoods);
    }

}
